package com.example.demo.thread;

public class ThreadTest11 extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("Hello from " + this.getName() + this.currentThread().getId());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        ThreadTest11 t1 = new ThreadTest11();
        t1.setName("Thread-1");
        System.out.println("Starting thread: " + t1.getName());
        t1.start();
        try {
            // Wait for the thread to finish
            // 等待线程执行完成后释放CPU资源
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ThreadTest11 t2 = new ThreadTest11();
        t2.setName("Thread-2");
        System.out.println("Starting thread: " + t2.getName());
        t2.start();
    }


}
